﻿using AFanDa.DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace AFanDa.BLL
{
    public class BaseService<T> : IBaseService<T> where T : class, new()
    {

        IRepository<T> _repository = null;
        public BaseService()
        {
            _repository = new SqlRepository<T>();
        }


        public void Add(T t)
        {
            _repository.Add(t);
        }

        public void AddRange(IEnumerable<T> Ie)
        {
            _repository.AddRange(Ie);
        }

        public void Delete(T t)
        {
            _repository.Delete(t);
        }

        public void DeleteRange(IEnumerable<T> Ie)
        {
            _repository.DeleteRange(Ie);
        }

        public IQueryable<T> QueryAll(Expression<Func<T, bool>> where = null)
        {
            return _repository.QueryAll(where);
        }

        public IQueryable<T> QueryAll<type>(Expression<Func<T, type>> order, bool isAsc = true, Expression<Func<T, bool>> where = null)
        {
            return _repository.QueryAll(order, isAsc, where);

        }

        public IQueryable<T> QueryAll<type>(out int total, int? page, int? limit, Expression<Func<T, type>> order, bool isAsc, Expression<Func<T, bool>> where = null)
        {
            return _repository.QueryAll(out total, (page - 1) * limit, limit, order, isAsc, where);
        }

     

        public int SaveChange()
        {
            return _repository.SaveChange();
        }

        public void Update(T t)
        {
            _repository.Update(t);
        }

        public void UpdateRange(IEnumerable<T> Ie)
        {
            _repository.UpdateRange(Ie);
        }
    }

}
